import type { ConsultTypeEnum, HospitalTypeEnum, PayMethodEnum } from '@/enums'
import type {
  ConsultOrderItem,
  OrderListResult,
  ConsultOrderPreData,
  DoctorPage,
  FollowType,
  KnowledgePage,
  KnowledgeParams,
  OrderListParams,
  PageParams,
  PartialConsult
} from '@/types/consult'
import type { EvaluateDoctorForm } from '@/types/room'
import request from '@/utils/request'

// 获取首页 页签项列表
export const getKnowledgePage = (params: KnowledgeParams) =>
  request<KnowledgePage>('/patient/home/knowledge', 'GET', params)

// 获取首页 推荐关注的医生列表
export const getDoctorList = (params: PageParams) =>
  request<DoctorPage>('/home/page/doc', 'GET', params)

// 切换关注
export const followOrUnfollow = (id: string, type: FollowType = 'doc') =>
  request('/like', 'POST', { id, type })

// 获取科室列表
export const getDeptList = () => request<DoctorPage[]>('dep/all')

// 图片上传
export const uploadFile = (data: FormData) => {
  return request<{ id: string; url: string }>('upload', 'POST', data)
}

// 问诊-支付页面-计算就诊信息和抵扣信息(获取优惠卷信息)
export const getOrderPre = (params: {
  type: ConsultTypeEnum
  illnessType: HospitalTypeEnum
}) => {
  // eslint-disable-next-line prettier/prettier
  return request<ConsultOrderPreData>('/patient/consult/order/pre', 'GET', params)
}

// 支付
export const createOrder = (data: PartialConsult) => {
  // eslint-disable-next-line prettier/prettier
  return request<{ id: string }>('/patient/consult/order', 'POST', data)
}

// 发起支付
export const payMethod = (data: {
  paymentMethod: PayMethodEnum
  orderId: string
  payCallback: string
}) => {
  // eslint-disable-next-line prettier/prettier
  return request<{ payUrl: string }>('/patient/consult/pay', 'POST', data)
}

// 获取订单详情
export const getOrderDetail = (params: { orderId: string }) => {
  return request<ConsultOrderItem>(
    '/patient/consult/order/detail',
    'get',
    params
  )
}

// 根据处方id获取处方图片
export const getPrescriptionPicUrl = (id: string) => {
  return request<{ url: string }>(`/patient/consult/prescription/${id}`)
}

// 评价医生
export const evaluateDoctor = (data: EvaluateDoctorForm) => {
  return request<{ id: string }>(`/patient/order/evaluate`, 'POST', data)
}

// 问诊订单列表
export const getConsultList = (params: OrderListParams) => {
  return request<OrderListResult>('/patient/consult/order/list', 'GET', params)
}

// 取消订单
export const cancelOrder = (id: string) => {
  return request(`/patient/order/cancel/${id}`, 'PUT')
}
